/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aptech.campaign.entities;

import com.aptech.campaign.component.PropertyIndex;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Tai Nguyen
 */
public class Product implements PropertyIndex {

    private int productID;
    private String productName;
    private float price;
    private String info;
    private boolean status;
    private String lastError;

    /**
     *  boolean value
     * @return
     */
    public boolean validate() {
        Pattern pattern = Pattern.compile("[0-9]+[.]?[0-9]+");
        Matcher m = pattern.matcher(String.valueOf(price));
        if (!m.matches()) {
            setLastError("Please enter numeric value for Price!");
            return false;
        }
        return true;
    }

    /**
     * @return the productID
     */
    public int getProductID() {
        return productID;
    }

    /**
     * @param productID the productID to set
     */
    public void setProductID(int productID) {
        this.productID = productID;
    }

    /**
     * @return the productName
     */
    public String getProductName() {
        return productName;
    }

    /**
     * @param productName the productName to set
     */
    public void setProductName(String productName) {
        this.productName = productName;
    }

    /**
     * @return the price
     */
    public float getPrice() {
        return price;
    }

    /**
     * @param price the price to set
     */
    public void setPrice(float price) {
        this.price = price;
    }

    /**
     * @return the status
     */
    public boolean isStatus() {
        return status;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(boolean status) {
        this.status = status;
    }

    /**
     * @return the lastError
     */
    public String getLastError() {
        return lastError;
    }

    /**
     * @param lastError the lastError to set
     */
    public void setLastError(String lastError) {
        this.lastError = lastError;
    }

    /**
     * @return the info
     */
    public String getInfo() {
        return info;
    }

    /**
     * @param info the info to set
     */
    public void setInfo(String info) {
        this.info = info;
    }

    public Object getPropertyValue(int index) {
        String value = "";
        switch (index) {
            case 2:
                value = this.getProductName();
                break;
            case 3:
                value = String.valueOf(this.getPrice());
                break;
            case 4:
                value = this.getInfo();
                break;
            case 5:
                value = String.valueOf(this.isStatus());
                break;
        }
        return value;
    }

    public void setPropertyValue(int index, Object value) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Class getPropertyClass(int index) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
